package com.eco
{
	import com.eco.*;
	import com.framework.GameDataController;
	
	import flash.display.MovieClip;
	import flash.events.*;
	import flash.net.*;
	import flash.ui.Mouse;
	import flash.utils.*;
	import flash.xml.*;
	
	public class StageManager extends MovieClip
	{
		private var Loader:URLLoader;
		private var xmlData:XML;
		private var _URL:String;
		private var xmlDataURL:URLRequest;
		private var xmlLoader:URLLoader;
		
		private var bLoadFinished:Boolean;
		
		private var stgCurrentStage:GameStage;//关卡
		public var iState:int;
		
		public var isPaused:Boolean = false;
		
		private var stage_id:int;
		private var level_id:int;
		
		public function StageManager()
		{
			iState = -1;
		}
		
		public function StartStage(scene:int, level:int):void
		{
			stage_id = scene;
			level_id = level;
			if(stgCurrentStage == null)
			{
				stgCurrentStage = new GameStage(scene,level, GameDataController.getInstance().xmlData);
				addChild(stgCurrentStage);
			}else{
				EndStage();
			}
		}
		
		public function RestartStage():void
		{
			StartStage(stage_id,level_id);
		}
		
		public function EndStage():void
		{
			stgCurrentStage.Clear();
		}
		
		public function Update():void
		{
			iState = stgCurrentStage.iState;
			if(iState == GameStage.STAGE_LOSE )
			{
				Pause();
			}
		}
		
		public function Pause():void
		{
			if(isPaused == false)
			{
				stgCurrentStage.Pause();
				isPaused = true;
			}
		}
		
		public function Continue():void
		{
			if(isPaused == true)
			{
				stgCurrentStage.Continue();
				isPaused = false;
			}
		}
		
		public function Clear():void
		{
			if(stgCurrentStage!=null)
			{
				stgCurrentStage.Clear();
				this.removeChild(stgCurrentStage);
			}
		}
		
		public function EndCurrentStage():void
		{
			Clear();
		}
	}
}